package com.rest.demo.Service;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;


import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;


@Configuration
@Data
@Component
@Service
@Slf4j
public class DysmtBdc {
    @Autowired
    private RestTemplate restTemplate; //此模板需要到config下配置


    //JAVA模拟RAW提交方式
    public String httpTest(String json,String Url) throws IOException {
//        System.out.println(API_ROOT);

        String DysmtBdcTestUrl = Url;
//      HttpClient httpClient = HttpClientBuilder.create().build();
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost post = new HttpPost(DysmtBdcTestUrl);
        StringEntity postingString = new StringEntity(json);// json传递
        post.setEntity(postingString);
        post.setHeader("Content-type", "application/json");
        HttpResponse response = httpClient.execute(post);
        String content = EntityUtils.toString(response.getEntity());
        // Log.i("test",content);
        System.out.println(content);
        return content;
    }
}







